package com.t216.dm216.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.t216.dm216.mapper.DmUserMapper;
import com.t216.dm216.pojo.DmUser;
import com.t216.dm216.pojo.dto.DmUserDTO;
import com.t216.dm216.service.DmUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DmUserServiceImpl implements DmUserService {
    @Resource
    private DmUserMapper dmUserMapper;
    @Override
    public DmUser getUserByPhone(String phone) {
        MPJLambdaWrapper<DmUser> lambdaWrapper = new MPJLambdaWrapper<>();
        lambdaWrapper.select(DmUser::getId,DmUser::getPhone,DmUser::getPassword);
        lambdaWrapper.eq(DmUser::getPhone,phone);
        return dmUserMapper.selectOne(lambdaWrapper);
    }

    @Override
    public DmUserDTO getUserById(Long id) {
        MPJLambdaWrapper<DmUser> lambdaWrapper = new MPJLambdaWrapper<>();
        lambdaWrapper.select(DmUser::getId,DmUser::getPhone, DmUser::getWxUserId, DmUser::getRealName, DmUser::getNickName, DmUser::getSex, DmUser::getIdCard,DmUser::getBirthday, DmUser::getCreatedTime, DmUser::getUpdatedTime, DmUser::getHobby);
        lambdaWrapper.selectAs(DmUser::getId,DmUserDTO::getUserId);
        lambdaWrapper.eq(DmUser::getId,id);
        return dmUserMapper.selectJoinOne(DmUserDTO.class,lambdaWrapper);
    }
}
